package com.planet.merchant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.planet.merchant.domain.PmsProductCode;
import com.planet.merchant.service.IPmsProductCodeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.planet.common.annotation.Log;
import com.planet.common.core.controller.BaseController;
import com.planet.common.core.domain.AjaxResult;
import com.planet.common.enums.BusinessType;

import com.planet.common.utils.poi.ExcelUtil;
import com.planet.common.core.page.TableDataInfo;

/**
 * 商品二维码Controller
 *
 * @author ruoyi
 * @date 2025-04-07
 */
@RestController
@RequestMapping("/merchant/code")
public class PmsProductCodeController extends BaseController
{
    @Autowired
    private IPmsProductCodeService pmsProductCodeService;

    /**
     * 查询商品二维码列表
     */
    @PreAuthorize("@ss.hasPermi('system:code:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsProductCode pmsProductCode)
    {
        startPage();
        List<PmsProductCode> list = pmsProductCodeService.selectPmsProductCodeList(pmsProductCode);
        return getDataTable(list);
    }

    /**
     * 导出商品二维码列表
     */
    @PreAuthorize("@ss.hasPermi('system:code:export')")
    @Log(title = "商品二维码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsProductCode pmsProductCode)
    {
        List<PmsProductCode> list = pmsProductCodeService.selectPmsProductCodeList(pmsProductCode);
        ExcelUtil<PmsProductCode> util = new ExcelUtil<PmsProductCode>(PmsProductCode.class);
        util.exportExcel(response, list, "商品二维码数据");
    }

    /**
     * 获取商品二维码详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:code:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pmsProductCodeService.selectPmsProductCodeById(id));
    }

    /**
     * 新增商品二维码
     */
    @PreAuthorize("@ss.hasPermi('system:code:add')")
    @Log(title = "商品二维码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsProductCode pmsProductCode)
    {
        return toAjax(pmsProductCodeService.insertPmsProductCode(pmsProductCode));
    }

    /**
     * 修改商品二维码
     */
    @PreAuthorize("@ss.hasPermi('system:code:edit')")
    @Log(title = "商品二维码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsProductCode pmsProductCode)
    {
        return toAjax(pmsProductCodeService.updatePmsProductCode(pmsProductCode));
    }

    /**
     * 删除商品二维码
     */
    @PreAuthorize("@ss.hasPermi('system:code:remove')")
    @Log(title = "商品二维码", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsProductCodeService.deletePmsProductCodeByIds(ids));
    }
}
